//
//  CallDetailsViewController.m
//  JinChengYun
//
//  Created by 金橙云 on 2017/3/1.
//  Copyright © 2017年 金橙云. All rights reserved.
//

#import "CallDetailsViewController.h"

#import "CallChangeViewController.h"
#import "DouSecondCell.h"
#import "DouDetailsCell.h"
#import "TodoHttpManager.h"
#import "PhoneGenJinVc.h"
@interface CallDetailsViewController ()<UITableViewDelegate,UITableViewDataSource>

{
    NSArray *_titleArr;
    NSMutableDictionary *_callDataDic;
    NSString *str;
    NSString *str1;
    NSString *str2;
    NSString *str3;
    NSString *str4;
    NSString *str5;
    NSString *str6;
    NSString *str7;
    NSString *str8;
    NSString *str9;
    NSString *str10;
    NSString *str11;
    NSString *str12;
    NSString *str13;
    NSString *str14;
    
    
    NSString *strNum;
}
@property(nonatomic,strong)UITableView *tabView;
@property(nonatomic,strong)NSMutableArray *allArr;
@end

@implementation CallDetailsViewController

-(void)viewWillAppear:(BOOL)animated
{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didTDGuPhoneDetails:) name:TDGuPhoneDetails object:nil];
    [_manager userGuWenPhoneDetailsID:_callID];
    
    self.tabBarController.tabBar.hidden  = YES;
}
-(void)didTDGuPhoneDetails:(NSNotification *)notifi
{
    if (notifi.object != nil)
    {
        int status = [[notifi.object objectForKey:@"status"]intValue];
        if (status == 1)
        {
            _callDataDic = [notifi.object objectForKey:@"data"];
            
            str = [_callDataDic objectForKey:@"caller_time"];
            str1 = [_callDataDic objectForKey:@"caller_name"];
            str2 = [_callDataDic objectForKey:@"caller_sex"];
            strNum =  [_callDataDic objectForKey:@"caller_phone"];
            str3 =  [_callDataDic objectForKey:@"khdj"];
            str4 = [_callDataDic objectForKey:@"ggtg"];
            str5 =  [_callDataDic objectForKey:@"tjqd"];
            str6 = [_callDataDic objectForKey:@"tjfs"];
            str7 =  [_callDataDic objectForKey:@"recommend_name"];
            str8 = [_callDataDic objectForKey:@"recommend_phone"];
            str9 =  [_callDataDic objectForKey:@"need_property"];
            str10 = [_callDataDic objectForKey:@"order_area"];
            str11 = [_callDataDic objectForKey:@"order_type"];
            str12 = [_callDataDic objectForKey:@"dhjl"];
            str13 = [_callDataDic objectForKey:@"remind_time"];
            
            
            _allArr = [[NSMutableArray alloc] initWithObjects:str,str1,str2,strNum,str3,str4,str5,str6,str7,str8,str9,str10,str11,str12,str13, nil];
            [self.tabView reloadData];
//            NSLog(@"11-----%@",str3);
//            NSLog(@"22-----%@",str4);
//            NSLog(@"33-----%@",str5);
//            NSLog(@"44-----%@",str6);
//            NSLog(@"55-----%@",str7);
//            NSLog(@"66-----%@",str8);
//            NSLog(@"77-----%@",str10);
//            NSLog(@"88-----%@",str11);
//            NSLog(@"99-----%@",str12);
//            NSLog(@"1111-----%@",str13);

        }
    }
}
-(void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:TDGuPhoneDetails object:nil];
}
- (void)viewDidLoad {
    [super viewDidLoad];
   self.title = @"来电跟进";
    self.view.backgroundColor = BgColor;
    _manager = [TodoHttpManager sharedManager];
   // _allArr = [NSMutableArray arrayWithCapacity:0];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didTDGuPhoneDetails:) name:TDGuPhoneDetails object:nil];
    [_manager userGuWenPhoneDetailsID:_callID];
    
    

    
    _callDataDic = [NSMutableDictionary dictionaryWithCapacity:0];
    _titleArr =[NSArray arrayWithObjects:@"来电时间 :",@"客户姓名 :",@"客户性别 :",@"联系方式 :",@"客户等级 :",@"广告推广 :",@"推广渠道 :",@"推介方式 :",@"推荐人姓名 :",@"推荐人电话 :",@"需求物业 :",@"需求面积 :",@"需求户型 :",@"电话记录 :",@"下次跟进日期 :", nil];

    _tabView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, B_WIDTH, B_HEIGHT) style:UITableViewStyleGrouped];
    _tabView.delegate = self;
    _tabView.dataSource = self;
    _tabView.rowHeight = 44;
    [self.view addSubview:_tabView];
    
    
}

//-(void)genJinBtnClick
//{
//    PhoneGenJinVc *jiVc = [[PhoneGenJinVc alloc] init];
//    jiVc.ID = [_callDataDic objectForKey:@"caller_id"];
//    //NSLog(@"",);
//    [self.navigationController pushViewController:jiVc animated:NO];
//}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    
    
    return _titleArr.count;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    return nil;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    static NSString *cellIndent = @"";
    if (indexPath.row == 3)
    {
        cellIndent = @"CellA";
        DouSecondCell *cell = [tableView cellForRowAtIndexPath:indexPath];
        if (cell ==nil)
        {
            cell = [[DouSecondCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndent];
            
         
            
        }
        strNum =  [_callDataDic objectForKey:@"caller_phone"];
        cell.secondLab.text = [NSString stringWithFormat:@"%@",strNum.length>0?strNum:@""];
        [cell setUpUIPbone:[_callDataDic objectForKey:@"caller_phone"]];
        cell.firstLab.text= @"联系电话:";
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];//取消点击
        return cell;
        
    }
    else
    {
        cellIndent = @"CellB";
        DouDetailsCell *cell = [tableView cellForRowAtIndexPath:indexPath];
        if (cell ==nil)
        {
            cell = [[DouDetailsCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndent];
            
            
        }
        if ([cell isKindOfClass:[DouDetailsCell class]])
        {
            if (_allArr.count != 0)
            {
                
                NSString *str0 = (NSString *)_allArr[indexPath.row];
                cell.secondLab.text = [NSString stringWithFormat:@"%@",str0];
                
            }
            
        }
        
       
        
        cell.firstLab.text = _titleArr[indexPath.row];
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];//取消点击
        return cell;
        
    }
    
}


-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc] init];
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame= CGRectMake(20, 25,B_WIDTH-20*2, 45);
    btn.layer.cornerRadius = 6;
    btn.backgroundColor = [UIColor orangeColor];
    [btn setTitle:@"修改" forState:0];
    [btn setTitleColor:[UIColor whiteColor] forState:0];
    [btn addTarget:self action:@selector(xiuGaiBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:btn];
    
    [self.view addSubview:view];
    return view;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 100;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 2;
}
-(void)xiuGaiBtnClick:(UIButton *)btn
{
    CallChangeViewController *callChangeVC = [[CallChangeViewController alloc] init];
    callChangeVC.cellDic = _callDataDic;
    callChangeVC.IDCall = _callID;
    if (self.isFirst==YES) {
        
    }else{
        callChangeVC.isSecond = YES;
        
    }

    [self.navigationController pushViewController:callChangeVC animated:NO];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
